<?php
/**
 * unpor_share模块定义
 *
 * @author benhailong
 * @url 
 */
defined('IN_IA') or exit('Access Denied');

class Zst_marketingModule extends WeModule {

    /**
     * 修改微擎官方入口页面
     */
    public function welcomeDisplay(){

        global $_W,$_GPC;

        $this->checkModuleFile();// 验证模块核心文件
        $this->session();// 设置session登录状态
        $this->jump_cms(); // 跳转到独立后台


//        $url = "{$_W['siteroot']}addons/{$_W['current_module']['name']}/cms/index.html";
//        echo $url;
    }

    private function checkModuleFile()
    {
        $module_file = __DIR__ . '/inc/web/public/index.php';
        !file_exists($module_file) && itoast('模块文件不存在', referer(), 'error');

        if (session_status() != PHP_SESSION_ACTIVE){
//            itoast('未开启session', referer(), 'error');
            session_start();
        }
    }

//单管理模式，自动登录。如果有管理员权限控制，那还是手动登录较好
    private function session()
    {
        @session_start();
        global $_W,$_GPC;
        $_SESSION['qy2019'] = [
            'wxapp' => [
                'wxapp_id' => $this->wechat_app['uniacid']
            ],
            'we7_data' => [
                'uniacid' => $_W['uniacid'], // 当前公众号ID,
                'user' => $_W['user'],
                'model_name' => $_W['current_module']['name'],
                'app_secret' => $this->wechat_app['secret'],
            ],
            'is_login' => true
        ];
    }

    private function jump_cms()
    {
        global $_W;
        $url = "{$_W['siteroot']}addons/{$_W['current_module']['name']}/cms/index.html";
//        $url = "{$_W['siteroot']}addons/{$_W['current_module']['name']}/inc/web/public/index.php";
        header('Location:' . $url);  //header跳转不好用，session，缓存等都无法传递。改用js跳转
        exit;

//        header('Location:'.url('site/entry',array('m'=>'unpor_qingming','do'=>'main','go'=>'index','dodo'=>'visit','operate'=>'list')));
    }

}
